package com.fqy.gmall.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fqy.gmall.common.result.Result;
import com.fqy.gmall.model.product.SkuInfo;
import com.fqy.gmall.product.service.ManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * User: fqy
 * Date: 2021/9/14
 * Time: 14:56
 * Describe: 商品属性sku管理
 */
@Api(tags = "商品属性SkuInfo管理")
@RestController
@RequestMapping("/admin/product")
public class SkuManageController {
    @Autowired
    private ManageService manageService;

    //添加sku之保存：保存skuInfo
    // /admin/product/saveSkuInfo
    @ApiOperation("添加sku之保存：保存skuInfo")
    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        manageService.saveSkuInfo(skuInfo);
        return Result.ok();
    }

    //商品属性skuInfo分页显示 /admin/product/list/{page}/{limit}
    @ApiOperation("商品属性skuInfo分页显示")
    @GetMapping("list/{page}/{limit}")
    public Result getSkuInfoPage(@PathVariable Long page,@PathVariable Long limit){
//        Page<SkuInfo> infoPage = new Page<>(page, limit);
        IPage<SkuInfo> skuInfoPage = manageService.getSkuInfoPage(page,limit);
        return Result.ok(skuInfoPage);
    }

    //  /admin/product/onSale/{skuId}
    @ApiOperation("上架：是否销售（1：是 0：否）")
    @GetMapping("onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId){
        //  调用服务层方法
        manageService.onSale(skuId);
        return Result.ok();
    }

    //  /admin/product/cancelSale/{skuId}
    @ApiOperation("下架：是否销售（1：是 0：否）")
    @GetMapping("cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId){
        //  调用服务层方法
        manageService.cancelSale(skuId);
        return Result.ok();
    }
}
